/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package unilearn.dao.hibernate;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import unilearn.dao.SubjectMarkerDAO;
import unilearn.vo.SubjectMarker;

/**
 *
 * @author Yat
 */
public class SubjectMarkerDAOImpl extends HibernateDAO implements SubjectMarkerDAO {

    public SubjectMarkerDAOImpl() {
        super();
    }

    public SubjectMarkerDAOImpl(SessionFactory sessionFactory) {
        super(sessionFactory);
    }

    @Override
    public void setSessionFactory(SessionFactory sessionFactory) {
        super.setSessionFactory(sessionFactory);
    }

    @Override
    public List<SubjectMarker> getAll() throws Exception {
        return super.getAll(SubjectMarker.class.getName());
    }

    @Override
    public SubjectMarker get(int id) throws Exception {
        Session s = sessionFactory.openSession();
        Transaction t = s.beginTransaction();

        try {
            Query query = s.createQuery("from " + SubjectMarker.class.getName() + " sm where sm.id = " + id);
            List<SubjectMarker> sms = query.list();
            if ((sms == null) || (sms.isEmpty())) {
                return null;
            }

            return sms.get(0);
        } finally {
            t.commit();
            s.close();
        }
    }

    @Override
    public List<SubjectMarker> find(SubjectMarker subjectMarker) throws Exception {
        return (List<SubjectMarker>) super.find(subjectMarker);
    }

    @Override
    public SubjectMarker insert(SubjectMarker subjectMarker) throws Exception {
        super.insert(subjectMarker);
        return subjectMarker;
    }

    @Override
    public SubjectMarker update(SubjectMarker subjectMarker) throws Exception {
        super.update(subjectMarker);
        return subjectMarker;
    }

    @Override
    public void delete(SubjectMarker subjectMarker) throws Exception {
        super.delete(subjectMarker);
    }
}
